/**
 * Created by Admin on 2018/1/12.
 */
define(function(require,exports,module){
    var tpl=require("./tpl/tradeStatisticalTpl.html");
    var loadingTpl = require("../common/tpl/loading.html");
    var template = require("template");
    require("../common/dialog.js");
    require("../common/qy-template");
    require("../common/highchart/highcharts.js");
    require("../common/highchart/linechart.js");
    require("../common/highchart/columnChart.js")

    /*获取数据范围列表*/
    var List = {
        getList:function(){
            /*获取区域和数据范围数据*/
            // $.ajax({
            //     url:window.jkconfig.webapiurlv+"analysis/dataType",
            //     success:function(data){
            //         var dataHtml = "";
            //         if(data.code == 0){
            //             /*在遍历data.DataTypeInfo,获取数据范围列表*/
            //             if(data.DataTypeInfo.length>0){
            //                 for(var i = 0 ;i<data.DataTypeInfo.length;i++){
            //                     dataHtml += '<option value="'+eval(data.DataTypeInfo[i].dataTypeValue)+'">'+data.DataTypeInfo[i].dataTypeName+'</option>'
            //                 }
            //                 $("[name=dataTypeValue]").append(dataHtml);
            //             }
            //         }else{
            //             $.showErr("获取数据范围列表失败!");
            //         }
            //     }
            // })
            /*获取table数据*/
            ajaxOperator(window.jkconfig.webapiurlv+"analysis/applicantIndustry?dataTypeValue=1");
        }
    }
    List.getList();


    $(function(){
        $("[name=dataTypeValue]").change(function(){
            $("#tradeStatisticalBox").html(loadingTpl);
            ajaxOperator(window.jkconfig.webapiurlv+"analysis/applicantIndustry?dataTypeValue="+$(this).val());
        })
        $("body").on("click",".btnExport",function(){
            window.location.href = window.jkconfig.webapiurlv + "analysisexport/applicantIndustry?dataTypeValue="+$("[name=dataTypeValue]").val()+"&"+api_key+"="+token;
        })
    })

    function ajaxOperator(url){
        $.ajax({
            url:url,
            success:function(data){
                if(data.code == 0){
                    if(data.info.length > 1){
                        $(".nodata-title").show();
                        $("#tradeStatisticalBox").hide();
                        var html = '<div class="nodata-title" style="height:270px;line-height:270px;">暂无数据</div>';
                        $("#RightSChart").html(html);
                    }else{
                        $(".nodata-title").hide();
                        $("#tradeStatisticalBox").show();
                        var html = template.compile(tpl)({data:data});
                        $("#tradeStatisticalBox").html(html);
                        var sourceYData = [],sourceXData = [];
                        for(var i = 0;i<data.info.length;i++){
                            sourceYData.push(data.info[i].sum);
                            sourceXData.push(data.info[i].industryName);
                        }
                        /*柱状图*/
                        var yData = [{  name: '权利人', data: sourceYData }];
                        var linechart = new ColumnChart({
                            dom: "RightSChart",
                            xData:sourceXData,
                            yData: yData,
                            title: "权利人行业分布"
                        });
                    }
                }
            }
        })
    }
})